<%@ page import="schoolsource.sql.SchoolDBSQL" %>
<%@ page import="schoolsource.model.*" %>
<%@ page import="schoolsource.gui.FormFields" %>
<%@ page import="schoolsource.security.SecurityToken" %>
<% SecurityToken st = (SecurityToken) request.getAttribute(FormFields.SESSION);
   String requestObject = (String) st.getValue(FormFields.TOKEN);
   int classnum = (new Integer((String) st.getValue(FormFields.CLASSNUM))).intValue();
   UserContainer studentC[] = (UserContainer[]) st.getValue("studentsInClass");
   ClassContainer classC[] = (ClassContainer[]) st.getValue("classContainer");
   String loginType = (String) request.getAttribute(FormFields.USRTYPE); 
   String schoolName = (String) request.getAttribute(FormFields.SCHOOLNAME);
%>
   


<HTML>
  <HEAD>
      <SCRIPT LANGUAGE="JavaScript">

          function cancelForm() {
              document.forms.enrollmentlist.<%= FormFields.LINKCLICKED %>.value = "Cancel";
              document.forms.enrollmentlist.submit();
          }
          
      function submitEnrollmentAction() {
          var d = top.frames.viewframe.document;
          for (var i = 0; i < d.forms.enrollmentlist.selection.length; i++) {
            if (d.forms.enrollmentlist.selection[i].checked) {
                if (2 == i) {
                    return;
                }
                d.forms.enrollmentlist.<%= FormFields.LINKCLICKED %>.value = d.forms.enrollmentlist.selection[i].value;
                break;
            }
          }
          if (d.forms.enrollmentlist.SELECTEDSTUDENT.value) {
              d.forms.enrollmentlist.<%= FormFields.PARAMETER %>.value = d.forms.enrollmentlist.SELECTEDSTUDENT.value;
          }
          else {
              for (var i = 0; i < d.forms.enrollmentlist.SELECTEDSTUDENT.length; i++) {
                  if (d.forms.enrollmentlist.SELECTEDSTUDENT[i].checked) {
                      d.forms.enrollmentlist.<%= FormFields.PARAMETER %>.value = d.forms.enrollmentlist.SELECTEDSTUDENT[i].value;
                      break;
                  }
              }
          }
          d.forms.enrollmentlist.submit();
      }

    function viewDetailedInfo(page, selectedItem) {
        top.frames.mainframe.document.forms[0].SUBLINK.value = selectedItem;
        top.frames.mainframe.submitPage(top.frames.mainframe.document, "EDITORPAGE", page);
        return false;
    }

      </SCRIPT>
  </HEAD>
  <BODY>
      <FORM NAME="enrollmentlist" METHOD="POST">
    <CENTER>
    <H3>Class Enrollment</H3>
    <div STYLE="font-family:sans-serif;font-size:13;">
    <%
        StringBuffer time = new StringBuffer(classC[classnum].getClassTime().toString());
        time.setCharAt(0, Character.toLowerCase(time.charAt(0)));
        out.println("The following is a list of students in your <B>"+classC[classnum].getAssociatedCourse().getCourseShortName().toString()+"</B> " + time);
    %>
    </div><BR>
    <!--noPrint--><div STYLE="font-family:sans-serif;font-size:13;">Select an action to perform and click on a student.</div><!--/noPrint-->
    </CENTER>
    <TABLE ALIGN="CENTER" BORDER="0">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CURRENT %>" VALUE="<%= FormFields.SUBFRAME %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.TOKEN %>" VALUE="<%= requestObject%>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.PARAMETER %>" VALUE="">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.LINKCLICKED %>" VALUE="">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CLASSNUM %>" VALUE="<%= classnum %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.SCHOOLNAME %>" VALUE="<%= schoolName %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.USRTYPE %>" VALUE="<%= loginType %>">
      <TR STYLE="font-family:sans-serif;font-size:13;font-weight:bold;">
        <TD><BR>
          <CENTER><!--noPrint--><INPUT TYPE="RADIO" NAME="selection" VALUE="<%= FormFields.STUDENTPROFILE %>" CHECKED>Student Profile<!--/noPrint-->
          <!--noPrint--><INPUT TYPE="RADIO" NAME="selection" VALUE="<%= FormFields.PROGRESSLINK %>">Progress Report<!--/noPrint--></CENTER>
          
        </TD>
        <TD>&nbsp;
        </TD>
      </TR>
    </TABLE>
&nbsp;<br>
    <TABLE ALIGN="CENTER" BORDER="0">
        <%
        if (studentC != null) {
            for (int i = 0; i < studentC.length; i+=4) {
                out.println("<TR STYLE=\"font-family:sans-serif;font-size:13;\">");
                out.println("<TD><input type=\"radio\" name=\"SELECTEDSTUDENT\" value=\"" + studentC[i].getAssignedID().toString() + "\" " + ((i==0)?"CHECKED":"") + "><a STYLE=\"text-decoration:none;color:black;\">" + studentC[i].getLastName() + ", " + studentC[i].getFirstName() + "</a></TD>");
                out.println("<TD>&nbsp;&nbsp;&nbsp;&nbsp;</TD>");
                if (i + 1 < studentC.length) {
                    out.println("<TD><input type=\"radio\" name=\"SELECTEDSTUDENT\" value=\"" + studentC[i+1].getAssignedID().toString() + "\"><a STYLE=\"text-decoration:none;color:black;\">" + studentC[i+1].getLastName() + ", " + studentC[i+1].getFirstName() + "</a></TD>");
                    out.println("<TD>&nbsp;&nbsp;&nbsp;&nbsp;</TD>");
                }
                if (i + 2 < studentC.length) {
                    out.println("<TD><input type=\"radio\" name=\"SELECTEDSTUDENT\" value=\"" + studentC[i+2].getAssignedID().toString() + "\"><a STYLE=\"text-decoration:none;color:black;\">" + studentC[i+2].getLastName() + ", " + studentC[i+2].getFirstName() + "</a></TD>");
                    out.println("<TD>&nbsp;&nbsp;&nbsp;&nbsp;</TD>");
                }
                if (i + 3 < studentC.length) {
                    out.println("<TD><input type=\"radio\" name=\"SELECTEDSTUDENT\" value=\"" + studentC[i+3].getAssignedID().toString() + "\"><a STYLE=\"text-decoration:none;color:black;\">" + studentC[i+3].getLastName() + ", " + studentC[i+3].getFirstName() + "</a></TD>");
                }
                else {
                    out.println("<TD>&nbsp;</TD>");
                }
                out.println("</TR>");
            } 
        }
        %>
    </TABLE>
    &nbsp;<br>
    <TABLE ALIGN="CENTER" BORDER="0">
      <TR>
        <TD>
          <CENTER><INPUT TYPE='BUTTON' NAME='<%= FormFields.BUTTONCLICKED %>' onClick='submitEnrollmentAction()' VALUE='OK'></CENTER>
        </TD>
        <TD>&nbsp;
        </TD>
      </TR>
    </TABLE>
      </FORM>
  </BODY>
</HTML>
